package com.socene.kotlin.config

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.ApiInfo
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2

/**
 *Created by: Sorata 17/9/12 上午10:58
 *
 */
@Configuration
@EnableSwagger2
@ConditionalOnProperty(value = "swagger-enable", havingValue = "true") //开发-上线 是否开启文档
class SwaggerConfiguration {

    @Bean
    fun createRestApi(): Docket {
        return Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.socene.kotlin.controller"))
                .paths(PathSelectors.any())
                .build()
    }

    fun apiInfo(): ApiInfo {
        return ApiInfoBuilder()
                .title("API文档")
                .description("项目文档描述")
                .termsOfServiceUrl("www.baidu.com")
                .contact("sorata")
                .version("1.0")
                .license("内部")
                .build()
    }

}
